function getRootPath() {
    var pathName = window.location.pathname.substring(1);
    var webName = pathName == '' ? '' : pathName.substring(0, pathName
        .indexOf('/'));
    return window.location.protocol + '//' + window.location.host + '/'
        + webName + '/';
}


function login(){
    var username = $("#username").val();
    var password = $("#password").val();
    if(username == ""){
        alert("用户名不能为空");
        return;
    }
    if(password == ""){
        alert("密码不能为空");
        return;
    }
    $.ajax({
        type:"POST",
        url:getRootPath()+"/user/loginVal.do",
        data:{
            username:username,
            password:password
        },
        success:function(res){
            if(res == "noname"){
                alert("用户名不存在");
                return;
            }
            if(res == "pwderr"){
                alert("密码错误")
                return;
            }
            if(res == "yes"){
                window.location.href = getRootPath()+"/user/my";
            }
        }
    })


}